import request from '@/utils/axios/axios-service.ts'

/**
 * 消费券
 */
export const couponList = (params: any) => request.get('/coupon/list', {params: params})
export const couponInfo = (id: number) => request.get('/coupon/info/' + id)
export const couponSaveOrUpdate = (params: any, isCreate: boolean) => request.post(isCreate ? '/coupon/create' : '/coupon/update', params);
export const couponDelete = (id: number) => request.delete('/coupon/delete/' + id)
export const couponGiveAway = (params: any) => request.post( '/coupon/give_away', params);
export const couponSimpleList = (params: any) => request.get('/coupon/simple_list', {params: params})

/**
 * 用户消费券
 */
export const couponUserList = (params: any) => request.get('/coupon/user/list', {params: params})
export const couponUserSwitchDeleted = (id: number) => request.post('/coupon/user/switch_deleted/' + id)

export type Coupon = {
  id: number;
  status: number; // 状态 0:草稿 1:已启用
  type: number; // 适用类型 1:通用券
  title: string; // 标题
  amount: number; // 面值
  conditions: number; // 使用条件 0:无门槛 其他:订单满N元可用
  valid_type: number; // 有效期类型 0:无限制 1:指定时间范围 2:领取后N天有效
  valid_time_from: number; // 有效期开始时间
  valid_time_to: number; // 有效期结束时间
  valid_fixed_days: number; // 领取后N天有效
  issued_mode: number; // 领取方式 0:手动领取 1:后台发放
  issued_count?: number; // 总发放数量 0:无限制
  claimed_count: number; // 已领取数量
  used_count: number; // 已使用数量
  claim_limit: number; // 领取限制 0:无限制
  rule: string; // 规则描述
  deleted: boolean; // 是否删除 0:未删除 1:已删除
};
